package org.acghub.demo.mongodb.controller;

import com.alibaba.fastjson2.JSON;
import jakarta.annotation.Resource;
import lombok.extern.slf4j.Slf4j;
import org.acghub.demo.mongodb.entity.TestEntity;
import org.acghub.demo.mongodb.manager.TestEntityManager;
import org.springframework.web.bind.annotation.*;

@RestController()
@RequestMapping("/test_entity")
@Slf4j
public class TestEntityController {

    @Resource
    private TestEntityManager manager;


    @GetMapping("/generate")
    @ResponseBody
    public String generate() {
        log.info("generate start");
        TestEntity entity = manager.generate();
        log.info("generate end, eid={}", entity.getId());
        return JSON.toJSONString(entity);
    }

    @GetMapping("/query/{id}")
    @ResponseBody
    public String query(@PathVariable String id) {
        log.info("query start, id={}", id);
        return JSON.toJSONString(manager.query(Long.valueOf(id)));

    }

    @GetMapping("/random")
    @ResponseBody
    public String random() {
        log.info("random start");
        return JSON.toJSONString(manager.random());
    }
}
